package com.dj.uphome.web.controller.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.dj.common.web.controller.CoreCrudRestController;
import com.dj.uphome.web.service.system.SysRoleService;
import com.dj.uphome.web.vo.system.SysRoleVo;

/** 
 * 类名称：角色管理
 */
@Controller
@RequestMapping(value = "/role")
public class RoleController extends CoreCrudRestController{
	@Autowired
	private SysRoleService sysRoleService;
	

	/**
	 * 保存权信息
	 * @param menu
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/add",method = RequestMethod.POST,produces = { MediaType.APPLICATION_JSON_VALUE })
	public ResponseEntity<SysRoleVo> add(SysRoleVo vo) throws Exception {
		sysRoleService.create(vo);
		return  new ResponseEntity<SysRoleVo>(vo, HttpStatus.OK);
	}

	/**
	 * 删除角色
	 * @param menuId
	 * @param out
	 */
	@RequestMapping(value = "/del",method = RequestMethod.POST,produces = { MediaType.APPLICATION_JSON_VALUE })
	public ResponseEntity<SysRoleVo> delete(@RequestParam int roleId) throws Exception {
		sysRoleService.delete(roleId);
		return new ResponseEntity<>(HttpStatus.OK);
	}
	
	@RequestMapping(value = "/listPage", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE })
	public ResponseEntity<Page<SysRoleVo>> userPage(@PageableDefault(size = 10,sort="role_id",direction=Sort.Direction.DESC) Pageable pageRequest, SysRoleVo vo) throws Exception {
		return new ResponseEntity<>(sysRoleService.findPage(pageRequest, vo),HttpStatus.OK);
	}
	
}
